package com.seal.tsms.system.controller;

import com.seal.tsms.base.controller.BaseController;
import com.seal.tsms.base.util.DateUtils;
import com.seal.tsms.system.entity.SystemUser;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

/**
 * Created by seal.jing on 2015/12/26.
 */
@Controller
@RequestMapping("/system/systemUser")
public class SystemUserController extends BaseController<SystemUser,String> {
    @RequestMapping(value = "/new",method = RequestMethod.GET)
    public String create(){
        return "system/systemUser/add";
    }
    @RequestMapping(value = "/new",method = RequestMethod.POST)
    public String save(@ModelAttribute("user") SystemUser user, RedirectAttributes attr){
        user.setCreateTime(DateUtils.getCurrentDate());
        getSelfService().save(user);
        attr.addAttribute("id",user.getId());
        attr.addFlashAttribute("message","一条记录添加成功");
        return "redirect:/system/systemUser/show.do";
    }
    @RequestMapping(value = "/show")
    public String show(@RequestParam String id, ModelMap model){
        model.addAttribute("user",getSelfService().get(id));
        return "system/systemUser/show";
    }

}
